

package at.fhj.itm.metadata.impl.postgres;

import static at.fhj.itm.metadata.MetadataUtil.copyMetadataList;
import at.fhj.itm.metadata.Table;
import at.fhj.itm.metadata.impl.AbstractSchema;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Seuchter
 */
public class PostgresSchema extends AbstractSchema
        implements PostgresMetaDataItem  {

    private long oid;

    private List<PostgresTable> tables;
    private List<PostgresSequence> sequences;
    private List<PostgresProcedure> procedures;
    public PostgresSchema(long oid, String schema)
    {
        super(schema);
        this.oid = oid;
        tables = new ArrayList<PostgresTable>();
        sequences = new ArrayList<PostgresSequence>();
        procedures = new ArrayList<PostgresProcedure>();
    }

    protected void setTables(List<PostgresTable> tables)
    {
        this.tables.addAll(tables);
    }

    public long getOid()
    {
        return  oid;
    }

    @Override
    public String toString()
    {
        return String.format("[PostgresSchema oid: %d name:%s children: %d]", getOid(), getName(), getChildren().size());
    }

    public List<PostgresTable> getTables()
    {
        return tables;
    }
    @Override
    public List<PostgresSequence> getSequences()
    {
        return sequences;
    }

    public List<PostgresProcedure> getProcedures(){
        return procedures;
    }

    protected void setSequences(List<PostgresSequence> sequences)
    {
        this.sequences = sequences;
    }

    protected void setProcedures(List<PostgresProcedure> procs){
        this.procedures = procs;
    }

    public PostgresSchema copy() {
        PostgresSchema schema = new PostgresSchema(-1, getName());
        schema.setTables(copyMetadataList(getTables()));
        schema.setProcedures(copyMetadataList(getProcedures()));
        schema.setSequences(copyMetadataList(getSequences()));
        return schema;
   }

}
